$(document).ready(function(){
  window.Dock= window.top.NoticeDock.get();
});
function NoticeAdmin(){
}
/****
* 获取被选中的id项
*/
NoticeAdmin.getIDs= function(){
    var $chk=$('table.content input[name^="id"]:checked');
    if ($chk.length <=0){
      return null;
    }
    var id=new Array($chk.length);
    for (var i=0; i<$chk.length; i++){
      id[i]= $chk[i].value;
    }
    return id;
}
/****
* 通用callback, 参见 ThinkPHP.Action.ajaxReturn ()格式
*/
NoticeAdmin.callback= function(data){
    if (0==data.status){
      Dock.addAlert("修改失败, 没有记录被更新");
    } else{
      Dock.addAlert("操作成功, "+data.info.message+"条记录被更新");
      location.reload();
    }
}
/****
* 删除
*/
NoticeAdmin.del= function(id){
//TODO 状态返回
  var callback= NoticeAdmin.callback;
  if (!confirm("确认删除？")){
    return;
  }
  if (!id){
    id= NoticeAdmin.getIDs();
  }
  if (null==id){
    return false;
  }
  var url=$('#console').attr('action')+'del';
  $.post(url, {
                id: id,
                submit: 'del'
          },callback,'json');
};
/****
* 修改活动状态
*/
NoticeAdmin.state=function(id, state){
  var callback= NoticeAdmin.callback;
  if (!id){
    id= NoticeAdmin.getIDs();
  }
  if (null==state ||null==id){
    return false;
  }
  var url=$('#console').attr('action')+'state';
  $.post(url, {
                id: id,
                state:  state,
                submit: 'state'
          },callback,'json');
};
NoticeAdmin.role=function(id, role){
  var callback= NoticeAdmin.callback;
  if (!id){
    id= NoticeAdmin.getIDs();
  }
  if (null==role ||null==id){
    return;
  }
  var url=$('#console').attr('action')+'role';
  $.post(url, {
                id: id,
                role:  role,
                submit: 'role'
          },callback,'json');
};

$(document).ready(function(){
  $('table.content input#check_all').change(function(){
    //全选
    $('table.content :checkbox').attr('checked', this.checked);
  });
});
